package com.sky.mapper;

import com.sky.entity.Dish;
import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetmealDishMapper {

    /**
     * 根据菜品id批量查询菜品和对应的套餐id
     * @param dishIds
     * @return
     */
    List<SetmealDish> selectSetmealByDishIds(List<Long> dishIds);

    /**
     * 批量插入套餐菜品关系数据
     * @param setmealDishes
     * @param setmealId
     */
    void insertBatch(List<SetmealDish>  setmealDishes, Long setmealId);

    /**
     * 根据套餐id批量删除套餐菜品关系数据
     * @param setmealIds
     */
    void deleteByIds(List<Long> setmealIds);

    /**
     *
     * @param setmealIds
     * @return
     */
    @Select("select id, setmeal_id, dish_id, name, price, copies from setmeal_dish where setmeal_id = #{setmealIds}")
    List<SetmealDish> selectBySetmealId(Long setmealIds);

    /**
     * 根据套餐id查询菜品状态
     * @param setmealIds
     * @return
     */
    @Select("select count(*) from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealIds} and d.status = 0")
    Long selectDishCountBySetmealId(Long setmealIds);
}
